package com.aispeech.jarpc.op.post.v2;

public class PostEnv_v2 {
    private static final String JSON_TEMPLATE = "{" +
            "\\\"concurrency\\\":%d," +
            "\\\"smooth\\\":{\\\"use_txt_smooth\\\":%d}," +
            "\\\"punctuation\\\":{\\\"use_period_split\\\":%d}," +
            "\\\"smooth_punc_unite\\\":{\\\"switch_on\\\":%d,\\\"use_period_split\\\":%d,\\\"use_txt_smooth\\\":%d,\\\"separate_time\\\":%d}," +
            "\\\"ITN\\\":{\\\"use_inverse_txt\\\":%d}," +
            "\\\"sensitive\\\":{\\\"mgc_bin_path\\\":\\\"%s\\\"}," +
            "\\\"hotword\\\":{\\\"hotword_file_path\\\":\\\"%s\\\"}," +
            "\\\"POS\\\":{\\\"switch_on\\\":%d,\\\"wp_in_merge\\\":%d}," +
            "\\\"paragraph\\\":{\\\"switch_on\\\":%d}," +
            "\\\"pinyin\\\":{\\\"switch_on\\\":%d,\\\"use_tone\\\":%d}" +
            "}";

    private int concurrency;            // 顺滑&标点、语义分段、ITN 并发数
    private int puncSeparateTime;       // 认为同一说话人的词可以断开的时间间隔，单位ms，默认值3000
    private int useFullstop = 0;        // 1:按句尾标点聚合; 0:按任意标点聚合;
    private int useTxtSmooth = 0;       // 是否使用单顺滑模型做顺滑功能
    private int useSmoothPunc = 0;      // 1:使用顺滑&标点多任务模型做顺滑和标点功能; 0:使用各自独立的模型;
    private int useITN = 0;             // 1:启动逆文本转换; 0:关闭逆文本转换;
    private int usePOS = 0;             // 1:打开词性输出(默认值); 0:关闭词性输出(此时词性值永远不会出现s); use_segment打开时自动打开
    private int wpInOnebest = 0;        // 0:不在merge结果中使用特殊标记来对词性做标记(默认值); 1:在merge结果中增加特殊标记来标记词性词(同时依赖switch_on=1);
    private int useParagraph = 0;       // 0:关闭语义分段(默认值); 1:打开语义分段(此时merge结果的词性值中会出现g);
    private int usePinyin = 0;          // 0:关闭拼音(默认值); 1:打开拼音;
    private int useTone = 0;            // 0:不打开音调(默认值); 1:打开音调;
    private String sensitiveBinPath;    // "0":关闭敏感词检测(默认值); "/mnt/xx/mgc.bin":使用用户的敏感词检测; "buildin":表示使用资源自带的mgc.bin(调试用);
    private String hotwordFilePath;     // "0":关闭热词功能(默认值); "/mnt/xx/hotwords.txt":使用用户配置的热词后处理;

    public PostEnv_v2(int concurrency, int puncSeparateTime, boolean useFullstop, boolean useTxtSmooth, boolean useSmoothPunc, boolean useITN, boolean usePOS,
                      boolean wpInOnebest, boolean useParagraph, boolean usePinyin, boolean useTone, String sensitiveBinPath, String hotwordFilePath) {
        this.concurrency = concurrency;
        this.puncSeparateTime = puncSeparateTime;
        this.useFullstop = useFullstop ? 1 : 0;
        this.useTxtSmooth = useTxtSmooth ? 1 : 0;
        this.useSmoothPunc = useSmoothPunc ? 1 : 0;
        this.useITN = useITN ? 1 : 0;
        this.usePOS = usePOS ? 1 : 0;
        this.wpInOnebest = wpInOnebest ? 1 : 0;
        this.useParagraph = useParagraph ? 1 : 0;
        this.usePinyin = usePinyin ? 1 : 0;

        if (useTone) {
            this.usePinyin = 1;
            this.useTone = 1;
        } else {
            this.useTone = 0;
        }

        this.sensitiveBinPath = (sensitiveBinPath == null || sensitiveBinPath.isEmpty()) ? "0" : sensitiveBinPath;
        this.hotwordFilePath = (hotwordFilePath == null || hotwordFilePath.isEmpty()) ? "0" : hotwordFilePath;
    }

    @Override
    public String toString() {
        return String.format(
                JSON_TEMPLATE,
                concurrency,
                useTxtSmooth,
                useFullstop,
                useSmoothPunc,
                useFullstop,
                useTxtSmooth,
                puncSeparateTime,
                useITN,
                sensitiveBinPath,
                hotwordFilePath,
                usePOS,
                wpInOnebest,
                useParagraph,
                usePinyin,
                useTone
        );
    }
}
